<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <div>
          <a-collapse v-model="activeKey">
            <a-collapse-panel header="合同信息" key="1">
              <a-row class="form-row" :gutter="24">
                <a-col :lg="6">
                  <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy01', validatorRules.fxy01]" placeholder="请输入合同编号"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="6">
                  <a-form-item label="合同名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy02', validatorRules.fxy02]" placeholder="请输入合同名称"></a-input>
                  </a-form-item>
                </a-col>
              </a-row>
            </a-collapse-panel>
            <a-collapse-panel header="订单信息" key="2">
              <a-col :lg="8">
                <a-form-item label="额度小写" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy04', validatorRules.fxy04]" placeholder="请输入额度小写"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="额度大写" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy05', validatorRules.fxy05]" placeholder="请输入额度大写"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="额度开始" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-date
                    placeholder="请选择额度开始"
                    v-decorator="['fxy06', validatorRules.fxy06]"
                    :trigger-change="true"
                    style="width: 100%"
                  />
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="额度结束" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-date
                    placeholder="请选择额度结束"
                    v-decorator="['fxy07', validatorRules.fxy07]"
                    :trigger-change="true"
                    style="width: 100%"
                  />
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="期限月" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy08', validatorRules.fxy08]" placeholder="请输入期限月"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="其他授信使用条件" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy09', validatorRules.fxy09]" placeholder="请输入其他授信使用条件"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="违约金" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy10', validatorRules.fxy10]" placeholder="请输入违约金"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="担保最高额大写" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy11', validatorRules.fxy11]" placeholder="请输入担保最高额大写"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="抵押物" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy12', validatorRules.fxy12]" placeholder="请输入抵押物"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="权证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy13', validatorRules.fxy13]" placeholder="请输入权证号"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="面积" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy14', validatorRules.fxy14]" placeholder="请输入面积"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="抵押物价值" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy15', validatorRules.fxy15]" placeholder="请输入抵押物价值"></a-input>
                </a-form-item>
              </a-col>
              <a-col :lg="8">
                <a-form-item label="额度的其他担保" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input v-decorator="['fxy16', validatorRules.fxy16]" placeholder="请输入额度的其他担保"></a-input>
                </a-form-item>
              </a-col>
            </a-collapse-panel>
            <a-collapse-panel header="公证信息" key="3">
              <a-row class="form-row" :gutter="24">
                <a-col :lg="8">
                  <a-form-item label="公证处" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy03', validatorRules.fxy03]" placeholder="请输入公证处"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="8">
                  <a-form-item label="邮寄地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy17', validatorRules.fxy17]" placeholder="请输入邮寄地址"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="8">
                  <a-form-item label="收件人电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy18', validatorRules.fxy18]" placeholder="请输入收件人电话"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="8">
                  <a-form-item label="是否办理强制执行公证" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input
                      v-decorator="['fxy19', validatorRules.fxy19]"
                      placeholder="请输入是否办理强制执行公证"
                    ></a-input>
                  </a-form-item>
                </a-col>

                <a-col :lg="8">
                  <a-form-item label="公证状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy20', validatorRules.fxy20]" placeholder="请输入公证状态"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="8">
                  <a-form-item label="公证书" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-input v-decorator="['fxy21', validatorRules.fxy21]" placeholder="请输入公证书"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :lg="8"></a-col>
              </a-row>
            </a-collapse-panel>
          </a-collapse>
        </div>

        <!-- <a-form-item label="备注3" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy22', validatorRules.fxy22]" placeholder="请输入备注3"></a-input>
        </a-form-item>
        <a-form-item label="备注4" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy23', validatorRules.fxy23]" placeholder="请输入备注4"></a-input>
        </a-form-item>
        <a-form-item label="备注5" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'fxy24', validatorRules.fxy24]" placeholder="请输入备注5"></a-input>
        </a-form-item> -->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import JDate from '@/components/jeecg/JDate'

export default {
  name: 'FxyConcactModal',
  components: {
    JDate
  },
  data() {
    return {
      form: this.$form.createForm(this),
      title: '操作',
      width: 1400,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {
        fxy01: {},
        fxy02: {},
        fxy03: {},
        fxy04: {},
        fxy05: {},
        fxy06: {},
        fxy07: {},
        fxy08: {},
        fxy09: {},
        fxy10: {},
        fxy11: {},
        fxy12: {},
        fxy13: {},
        fxy14: {},
        fxy15: {},
        fxy16: {},
        fxy17: {},
        fxy18: {},
        fxy19: {},
        fxy20: {},
        fxy21: {},
        fxy22: {},
        fxy23: {},
        fxy24: {}
      },
      url: {
        add: '/gzgl01/fxyConcact/add',
        edit: '/gzgl01/fxyConcact/edit'
      }
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(
          pick(
            this.model,
            'fxy01',
            'fxy02',
            'fxy03',
            'fxy04',
            'fxy05',
            'fxy06',
            'fxy07',
            'fxy08',
            'fxy09',
            'fxy10',
            'fxy11',
            'fxy12',
            'fxy13',
            'fxy14',
            'fxy15',
            'fxy16',
            'fxy17',
            'fxy18',
            'fxy19',
            'fxy20',
            'fxy21',
            'fxy22',
            'fxy23',
            'fxy24'
          )
        )
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(
        pick(
          row,
          'fxy01',
          'fxy02',
          'fxy03',
          'fxy04',
          'fxy05',
          'fxy06',
          'fxy07',
          'fxy08',
          'fxy09',
          'fxy10',
          'fxy11',
          'fxy12',
          'fxy13',
          'fxy14',
          'fxy15',
          'fxy16',
          'fxy17',
          'fxy18',
          'fxy19',
          'fxy20',
          'fxy21',
          'fxy22',
          'fxy23',
          'fxy24'
        )
      )
    }
  }
}
</script>
